\ Advanced scanlines example
\  Simulates (to the best degree I've ever seen) the appearance of a videogame on the old CRT TV's.
\ Because my laptop's resolution is 1280x800, I'll probably be limited to a 320x200 effective widescreen resolution, and use
\ letterboxing on other monitors.

empty


Requires Quest
Requires OpenGL\EXT-FBO


desktop  1280 800  d= [if]
   desktop fullscreen
[else]
   1280 800 window
[then]
s" scanlines.png" Graphic: scanlines-gfx
s" castle01.png" Graphic: screenshot
320 200 Image: framebuffer
init-all

: draw-test-frame
   set-default-blendfunc
   screenshot bind-image
   GL_LINEAR texture!filter
   0 0 at
   0 0 320 200 texarea
   screen-w screen-h white texrect ;

: subtractive-blending
   blendfunc:[ GL_DST_COLOR  GL_SRC_COLOR ;] ;

: additive-blending
   blendfunc:[ GL_ONE GL_ONE ;] ;


: draw-scanlines
   subtractive-blending
\   gl-alpha gl-disable
   scanlines-gfx bind-image
   GL_LINEAR texture!filter
   0 0 at
\   0 0 desktop 2 / swap 2 / swap texarea
   0 0 1280 2* 800 texarea
   screen-w screen-h $ffa0a0a0 texrect ;

{
draw-test-frame
draw-scanlines
}

320 200 framebuffer make-framebuffer

: frame
   set-default-blendfunc
   gl-alpha gl-enable

   framebuffer bind-framebuffer
      black clear-color
      cls
      framebuffer framebuffer-2dmode
      screenshot bind-image
      GL_NEAREST texture!filter
      0 0 at
      screenshot 0 0 320 200 draw-image-part
      mouse at
      50 red circlef
   unbind-framebuffer

   black clear-color
   cls
   2dmode

   disable-translucency
   0 0 at
   framebuffer bind-image
   GL_LINEAR texture!filter
   0 0 320 200 texarea
   screen-w screen-h white texrect

   enable-translucency
   draw-scanlines ;

: go   >seki begin frame end-frame <pause> key? until >ide ;

go

